package com.wanaofu.service;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import com.wanaofu.dao.QueryDAO;
import com.wanaofu.model.ProductInfo;

@Component
public class Initor implements ApplicationListener {

	@Override
	public void onApplicationEvent(ApplicationEvent event) {
		if(event instanceof ContextRefreshedEvent)  
        {
			System.out.println("=================all of beans have been inited===============");
			
			ApplicationContext context = ((ContextRefreshedEvent)event).getApplicationContext() ;

//			List<ProductInfo> list = (ProductService)context.getBean("productService").getAllProducts() ;

			QueryDAO queryDao = (QueryDAO)context.getBean("queryDAO") ;
			List<ProductInfo> list = (List<ProductInfo>)queryDao.getAll(ProductInfo.class);
			
			HomeServeice.init(list);
        }
	}  
}
